<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      //   1. 用户输入一个整数n：
      //   求1! + 2! + 3! + 4! + …… + n!的和
      //   叹号表示阶乘，如4! = 1 * 2 * 3 * 4

      function calculate(nums) {
        this.factorial = function () {
          console.log("您输入数字的是" + nums);
          var n = 0;
          var c = 1;
          for (var i = 1; i <= nums; i++) {
            c *= i;
            console.log("c是：" + c);
            n += c;
            console.log("n是：" + n);
          }
          console.log(nums + "的阶乘是：" + n);
          alert(nums + "的阶乘是：" + n);
        };
      }
      var nums = parseInt(prompt("请输入一个正整数"));
        // var comply = new calculate(nums);
        // comply.factorial();
      var comply = new calculate(nums).factorial();
    </script>
  </head>
  <body></body>
</html>
